/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Product.java
 *
 * Created on 01-04-2011, 06:12:34
 */

package GuiLayer;

import CtrLayer.CtrProduct;

/**
 *
 * @author Sharif
 */
public class Product extends javax.swing.JFrame {

    /** Creates new form Product */
    public Product() {
        initComponents();
         this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jID = new javax.swing.JLabel();
        jName = new javax.swing.JLabel();
        jPurchasePrice = new javax.swing.JLabel();
        jSalesPrice = new javax.swing.JLabel();
        jRentPrice = new javax.swing.JLabel();
        jCountryOfOrigin = new javax.swing.JLabel();
        jminStock = new javax.swing.JLabel();
        jTextID = new javax.swing.JTextField();
        jTextName = new javax.swing.JTextField();
        jTextPurchasePrice = new javax.swing.JTextField();
        jTextSalesPrice = new javax.swing.JTextField();
        jTextRentPrice = new javax.swing.JTextField();
        jTextCountryOfOrigin = new javax.swing.JTextField();
        jTextminStock = new javax.swing.JTextField();
        jButtonInsert = new javax.swing.JButton();
        jButtonUpdate = new javax.swing.JButton();
        jButtonSearch = new javax.swing.JButton();
        jButtonDelete = new javax.swing.JButton();
        jTextSupplierid = new javax.swing.JTextField();
        jminStock1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jID.setText("Id");

        jName.setText("Name");

        jPurchasePrice.setText("PurchasePrice");

        jSalesPrice.setText("SalesPrice");

        jRentPrice.setText("RentPrice");

        jCountryOfOrigin.setText("CountryOfOrigin");

        jminStock.setText("minStock");

        jTextID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextIDActionPerformed(evt);
            }
        });

        jTextminStock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextminStockActionPerformed(evt);
            }
        });

        jButtonInsert.setText("Insert New");
        jButtonInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInsertActionPerformed(evt);
            }
        });

        jButtonUpdate.setText("Update");
        jButtonUpdate.setMaximumSize(new java.awt.Dimension(85, 23));
        jButtonUpdate.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonUpdate.setPreferredSize(new java.awt.Dimension(85, 23));
        jButtonUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateActionPerformed(evt);
            }
        });

        jButtonSearch.setText("Search");
        jButtonSearch.setMaximumSize(new java.awt.Dimension(85, 23));
        jButtonSearch.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonSearch.setPreferredSize(new java.awt.Dimension(85, 23));
        jButtonSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSearchActionPerformed(evt);
            }
        });

        jButtonDelete.setText("Delete");
        jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteActionPerformed(evt);
            }
        });

        jTextSupplierid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextSupplieridActionPerformed(evt);
            }
        });

        jminStock1.setText("supplierid");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButtonInsert)
                        .addGap(16, 16, 16)
                        .addComponent(jButtonUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addComponent(jButtonDelete))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jID, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jName)
                            .addComponent(jPurchasePrice)
                            .addComponent(jSalesPrice)
                            .addComponent(jCountryOfOrigin)
                            .addComponent(jRentPrice)
                            .addComponent(jminStock)
                            .addComponent(jminStock1))
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextSupplierid, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(jTextPurchasePrice, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(jTextSalesPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(jTextRentPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(jTextCountryOfOrigin, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(jTextName, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextID, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextminStock, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jID)
                    .addComponent(jTextID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jName)
                    .addComponent(jTextName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPurchasePrice)
                    .addComponent(jTextPurchasePrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSalesPrice)
                    .addComponent(jTextSalesPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRentPrice)
                    .addComponent(jTextRentPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCountryOfOrigin)
                    .addComponent(jTextCountryOfOrigin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextminStock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jminStock))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextSupplierid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jminStock1))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonInsert)
                    .addComponent(jButtonUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonDelete))
                .addGap(36, 36, 36))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextIDActionPerformed

    private void jButtonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateActionPerformed
	CtrProduct ctrP = new CtrProduct();
	int id = Integer.parseInt(jTextID.getText());
	String name = jTextName.getText();
	double PurchasePrice = Double.parseDouble(jTextPurchasePrice.getText());
	double RentPrice = Double.parseDouble(jTextRentPrice.getText());
	double SalesPrice = Double.parseDouble(jTextSalesPrice.getText());
        String CountryOfOrigin = jTextCountryOfOrigin.getText();
        int minStock = Integer.parseInt(jTextminStock.getText());
        int supplierId = Integer.parseInt(jTextSupplierid.getText());
	int res = ctrP.updateProd(id, name, PurchasePrice, RentPrice, SalesPrice, CountryOfOrigin, minStock, supplierId);
	//TODO do something with res
    }//GEN-LAST:event_jButtonUpdateActionPerformed

    private void jButtonSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSearchActionPerformed
	CtrProduct ctrP = new CtrProduct();
	ModelLayer.Product c = ctrP.findById(jTextID.getText());
	jTextName.setText(c.getName());
	jTextPurchasePrice.setText(Double.toString(c.getPurchasePrice()));
	jTextSalesPrice.setText(Double.toString(c.getSalesPrice()));
	jTextRentPrice.setText(Double.toString(c.getRentPrice()));
	jTextCountryOfOrigin.setText(c.getCountryOfOrigin());
        jTextSupplierid.setText(Integer.toString(c.getSupplierId()));
    }//GEN-LAST:event_jButtonSearchActionPerformed

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
	// TODO delete option
	CtrProduct ctrP = new CtrProduct();
	int id = Integer.parseInt(jTextID.getText());
	int res = ctrP.deleteProduct(id);
	//TODO do something with res
    }//GEN-LAST:event_jButtonDeleteActionPerformed

    private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInsertActionPerformed
	CtrProduct ctrP = new CtrProduct();
	String name = jTextName.getText();
	double purchasePrice = Double.parseDouble(jTextPurchasePrice.getText());
	double salesPrice = Double.parseDouble(jTextSalesPrice.getText());
	double rentPrice = Double.parseDouble(jTextRentPrice.getText());
        String countryOfOrigin = jTextCountryOfOrigin.getText();
        int minStock = Integer.parseInt(jTextminStock.getText());
        int supplierId = Integer.parseInt(jTextSupplierid.getText());
	int res = ctrP.insertNewProd(name, purchasePrice, salesPrice, rentPrice, countryOfOrigin, minStock, supplierId);
	//TODO do something with res
    }//GEN-LAST:event_jButtonInsertActionPerformed

    private void jTextminStockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextminStockActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextminStockActionPerformed

    private void jTextSupplieridActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextSupplieridActionPerformed
    {//GEN-HEADEREND:event_jTextSupplieridActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextSupplieridActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Product().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonInsert;
    private javax.swing.JButton jButtonSearch;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JLabel jCountryOfOrigin;
    private javax.swing.JLabel jID;
    private javax.swing.JLabel jName;
    private javax.swing.JLabel jPurchasePrice;
    private javax.swing.JLabel jRentPrice;
    private javax.swing.JLabel jSalesPrice;
    private javax.swing.JTextField jTextCountryOfOrigin;
    private javax.swing.JTextField jTextID;
    private javax.swing.JTextField jTextName;
    private javax.swing.JTextField jTextPurchasePrice;
    private javax.swing.JTextField jTextRentPrice;
    private javax.swing.JTextField jTextSalesPrice;
    private javax.swing.JTextField jTextSupplierid;
    private javax.swing.JTextField jTextminStock;
    private javax.swing.JLabel jminStock;
    private javax.swing.JLabel jminStock1;
    // End of variables declaration//GEN-END:variables

}
